package com.woniuxy.exam.controller;

import com.woniuxy.commons.entity.ExamType;
import com.woniuxy.commons.entity.ResponseEntity;
import com.woniuxy.exam.service.ExamTypeService;
import com.woniuxy.exam.utils.TreeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zouyang
 * @date 2020/8/3 - 22:30
 */
@RestController
@RequestMapping("/examtype")
public class ExamTypeController {
    @Autowired
    private ExamTypeService examTypeService;


    @RequestMapping("/menu")
    public List<ExamType> getMenu(){
        List<ExamType> examTypes = examTypeService.selectAll();
        return TreeUtils.getExamTypeMenu(examTypes);
    }

    @PostMapping("/add")
    public ResponseEntity add(ExamType examType){
        if(examType.getPid()==null){
            examType.setPid(0);
        }
        int res = examTypeService.insert(examType);
        if (res==1){
            return ResponseEntity.SUCCESS_RESPONSE;
        }
        return new ResponseEntity(500,"出现异常");
    }

}
